package com.woniuxy.project115.kaer.tenant.consumer;

import com.woniuxy.project115.kaer.tenant.entity.ServiceType;
import com.woniuxy.project115.kaer.tenant.mapper.ServiceTypeMapper;
import com.woniuxy.project115.kaer.tenant.service.ServiceTypeService;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @author HuH
 * @version 1.0
 * @CreatTime 2025-02-27 17:29
 * @description
 */
@Component
public class UpdateCacheConsumer {
    @Resource
    private ServiceTypeMapper serviceTypeMapper;

    @Resource
    private RedisTemplate<String, Object> redisObjectTemplate;

    @RabbitListener(queues = "update_cache_queue")
    @RabbitHandler
    public void updateCache(String key) {
        List<ServiceType> list = serviceTypeMapper.selectList(null);
        redisObjectTemplate.opsForValue().set(key, list, 30, TimeUnit.DAYS);
    }
}
